package com.ourteam.workspace.api;

import org.apache.commons.lang3.StringUtils;

import com.ourteam.frame.web.AbstractSearchModel;
import com.ourteam.workspace.dao.IWorkspaceResourceBusinessPackageRelateDAO;
import com.ourteam.workspace.dao.WorkspaceResourceBusinessPackageRelateDAOQueryBean;
import com.ourteam.workspace.domain.WorkspaceResourceBusinessPackageRelateBean;

public class ResourceRelatedBusinessPackageSearchModel
		extends AbstractSearchModel<WorkspaceResourceBusinessPackageRelateDAOQueryBean> {

	private long workspaceResourceId;

	private long workspaceId;

	private Long domainId;

	private String packageName;

	private String packageType;

	@Override
	public String getMappedDAOField(String aProperty) {
		return WorkspaceResourceBusinessPackageRelateBean.getMappedDAOField(aProperty);
	}

	@Override
	protected void doBuildQueryBean(WorkspaceResourceBusinessPackageRelateDAOQueryBean queryBean) throws Exception {
		WorkspaceResourceBusinessPackageRelateDAOQueryBean.Criteria criteria = queryBean.createCriteria();
		if (workspaceResourceId != 0) {
			criteria.andWorkspaceResourceIdEqualTo(workspaceResourceId);
		}
		if (workspaceId != 0) {
			criteria.andWorkspaceIdEqualTo(workspaceId);
		}

		if (this.domainId != null && this.domainId.longValue() != 0) {

			criteria.andBusinessDomainIdEqualTo(domainId);

		}

		if (StringUtils.isNoneBlank(this.packageName)) {

			criteria.andBusinessPackageNameLike(packageName);
		}

		if (StringUtils.isNoneBlank(this.packageType)) {
			criteria.andBusinessPackageTypeEqualTo(packageType);
		}

		if (queryBean.getSortProperties().isEmpty()) {
			queryBean.setSortProperty(IWorkspaceResourceBusinessPackageRelateDAO.BusinessPackageType);
			queryBean.setSortProperty(IWorkspaceResourceBusinessPackageRelateDAO.ResourceOrderIndex);
		}

	}

	public long getWorkspaceResourceId() {
		return workspaceResourceId;
	}

	public void setWorkspaceResourceId(long workspaceResourceId) {
		this.workspaceResourceId = workspaceResourceId;
	}

	public long getWorkspaceId() {
		return workspaceId;
	}

	public void setWorkspaceId(long workspaceId) {
		this.workspaceId = workspaceId;
	}

	public Long getDomainId() {
		return domainId;
	}

	public void setDomainId(Long domainId) {
		this.domainId = domainId;
	}

	public String getPackageName() {
		return packageName;
	}

	public void setPackageName(String packageName) {
		this.packageName = packageName;
	}

	public String getPackageType() {
		return packageType;
	}

	public void setPackageType(String packageType) {
		this.packageType = packageType;
	}

	

}
